package org.brownflat.watergate.dao;

import org.brownflat.watergate.domain.ReviewState;
import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;

import static org.hibernate.criterion.Restrictions.eq;
import static org.hibernate.criterion.Restrictions.isNull;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
@Repository
public class ReviewStateDAO extends AbstractHibernateDAO<ReviewState> {
    public ReviewStateDAO() {
        super(ReviewState.class);
    }

    public ReviewState findByName(String name) {
        Criteria criteria = getCriteria().add(eq("name", name));
        return (ReviewState) criteria.uniqueResult();
    }

    public ReviewState findInitialState() {
        Criteria criteria = getCriteria().add(isNull("previousState"));
        return (ReviewState) criteria.uniqueResult();
    }
}
